/**
 * Created by John on 2015/10/9.
 */
$(document).ready(function () {

});
(function () {
    basic.deviceReady = function () {
        if(!vars.userInfo){
            mc.getUserInfo(function (data) {
                vars.userInfo = JSON.parse(data);
                mc.showContent()
            })
        }
    };

    // 验证输入并修改密码
    util.rightButtonEventCallback = function () {
        //alert("右侧按钮点击")
        if(!$.trim($("#oldPassword").val()) || !$.trim($("#newPassword").val()) || !$.trim($("#checkNewPassword").val())) {
            mc.alert("请输入必要信息！", function () {
            });
            return;
        }
        if($("#newPassword").val() != $("#checkNewPassword").val()) {
            mc.alert("两次密码输入不一致，请重新输入！", function () {
               $("#newPassword").focus();
            });
            return;
        }
        var options = {
            username: vars.userInfo.loginname,
            oldpwd: $("#oldPassword").val(),
            newpwd: $("#newPassword").val()
        };
        if (mc.device == iOS) {
            mc.notification("提交中...", "Normal");
        }
        service.modPwd(options, function (data) {
            if (parseInt(data.status) == 500) {
                if (mc.device == iOS) {
                    mc.notification(data.exception, "Failed");
                } else {
                    mc.alert(data.exception);
                }
                $("#oldPassword").val("");
                return;
                /*mc.alert(data.exception, function () {
                    return;
                })*/
            } else {
                if (mc.device == iOS) {
                    mc.notification("", "Close");
                }
                mc.alert("密码修改成功，请重新登录！", function () {
                    mc.logOutUser();
                });
            }
        });
    };

    document.addEventListener('rightButtonEvent', util.rightButtonEventCallback, false);

})();